Enumeration variable types are useful in programming languages where a programmer wishes to specify potential values of a variable and possibly define special methods that operate on the variables. Previous methods of creating, modifying and deleting enumeration variable types create potential for programmer error.
A type system in a programming language specifies what type of variables may exist in the programming language. Example types include integer numbers, floating point numbers and characters. Example data structures include objects in objected-oriented programming languages, arrays and lists.
An ‘enumerated variable type’ is a type of variable used in programming languages for which a finite set of legal values are defined in advance. During programming, a list of the possible values is defines defined by a programmer. For example, an enumerated variable type, called “Days” may be defined, which may have any one of the following legal values: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, and Sunday. As another example, an enumerated variable type “Traffic_Light” may take possible values of Green, Yellow, and Red.
An enumerated variable is used in programming to allow the programmer to improve type safety of the resulting code and improve code readability. Type safety prevents the programmer from accidentally or deliberately assigning a value of an incorrect type to a variable. A prior solution to create enumerated types was to have integer variables and assign integer values as possible values. This solution provided neither type safety nor improved code readability. Another prior solution was to have integer variables and assign integer constants as possible values. This solution improved code readability but did not provide type safety.
Previously, creating an enumerated variable was a tedious process involving multiple steps in many programming languages. In one programming language, a new domain is created with fixed value type codes. A new data element is created referring to this domain. Finally, a type pool is created with symbolic names that are defined with constant values. This creates redundant data scattered throughout a source code of an application.